package com.xdf.data_transmitter.utils;

import com.xdf.data_transmitter.model.HeartBeat;
import com.xdf.data_transmitter.service.GPrintingdyeingnameService;
import com.xdf.data_transmitter.service.HeartBeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Configuration
@EnableScheduling
public class Schedule {
    @Autowired
    private DataTransmitter trans;
    @Autowired
    private HeartBeatService heartBeatService;
    @Autowired
    private GPrintingdyeingnameService millService;

    // 24小时上传，每51秒上传一次
    @Scheduled(cron = "0/51 * * * * ?")
    public void uploadProcess(){
        trans.uploadProcess();
    }

    // 24小时上传，每59秒上传一次
    @Scheduled(cron = "0/57 * * * * ?")
    public void uploadRoll(){
        trans.uploadRoll();
    }

    // 24小时上传，每47分上传一次
    @Scheduled(cron = "0 0/47 * * * ?")
    public void uploadSurface(){
        HeartBeat record = new HeartBeat();
        String mill = millService.getMillName();
        record.setMill(mill);
        record.setErp_time(new Date());
        record.setFlag("data_transmitter");
        int ret = heartBeatService.insertSelective(record);
    }
}
